#!/usr/bin/env python
#
# -------------------------------
# projects/python/collatz/main.py
# Copyright (C) 2009
# Glenn P. Downing
# -------------------------------

# To run the program
#     main.py < Collatz.in > Collatz.out

# To document the program
#     pydoc -w main

# -------
# globals
# -------

i = 0 # input: don't change after reading
j = 0 # input: don't change after reading
v = 0 # output
carray = [] # cache for cycle length for each number
done = False # a boolean that indicates whether the cache is built or not

# -----------
# InputReader
# -----------

class InputReader (object) :
    def read (self) :
        return raw_input()

# ------------
# OutputWriter
# ------------

class OutputWriter (object) :
    def write (self, *a) :
        for w in a :
            print w,
        print

# -------
# my_read
# -------

def my_read (r) :
    """
    reads an int into i and j
    return true if that succeeds, false otherwise
    """
    global i
    global j
    try :
        s = r.read()
    except EOFError :
        return False
    l = s.split()
    i = int(l[0])
    j = int(l[1])
    return True


# --------
# calc_cycle
# --------
       
def calc_cycle (m) :
       """
	calculates and returns the cycle length for a given int m
       """
       assert m >= 1
       c = 1
       while m != 1:           #loops until it hits 1
	assert m != 1
	if m < 500000:
          if carray[m] == 0:
            if m % 2 == 0:        #divide by 2 is m is even
              m = m >>1
              c += 1
            else:
              m = m + (m >> 1) + 1        #if its odd, (3m+1)/2
              c += 2                  #increment steps by 2
          else:
	    c = c + carray[m] - 1
	    m = 1
        else:
	  if m % 2 == 0:        #divide by 2 is m is even
              m = m >>1
              c += 1
          else:
              m = m + (m >> 1) + 1        #if its odd, (3m+1)/2
              c += 2                  #increment steps by 2

       assert m == 1
       assert c > 1
       return c
#--------
# make_list
#--------

def make_list(size):
	"""
	creates a list with a size that is passed in as a parameter
        fills the list with a bunch of 0s
        returns the filled out list 
	"""
   	assert size > 0
   	mylist = []
   	for i in range(size):	# appends the empty list with 0s
       	    mylist.append(0)
   	return mylist

# -------
# my_eval
# -------

def my_eval () :
    """
    computes the max cycle length in the range [i, j]
    and stores the result in v
    """
    global v
    global i
    global j
    global carray
    global done
    v = 1
    m = 0
    small = 0
    big = 0

    if i > j:
	big = i
	small = j
    else:
	big = j
        small = i

    assert big >= small
    x = small

    if done == False:
	carray = make_list(500000)
    	num = 1
    	count = 1
    	while num < 500000 :
	   carray[num] = count
	   num += num
	   count += 1
	done = True

    while x <= big:   		 #iterate from i up to j
	assert x <= big
	m = x
        cycle = 0
        if m < 500000 :
           if carray[m] == 0 :
	      cycle = calc_cycle(m)
	      assert cycle >= 1
	      carray[m] = cycle
	   else:
	      assert carray[m] >= 1
	      cycle = carray[m]
	else:
	  cycle = calc_cycle(m)
	if cycle > v:                #update v if the cycle is longer
             v = cycle  
        x += 1 

# --------
# my_print
# --------

def my_print (w) :
    """
    writes the values of i, j, and v
    """
    w.write(i, j, v)

# ----
# main file
# ----

def main () :
    """
    runs the program
    """
    global carray
 
#    carray = make_list(1000000)
#    num = 1
#    count = 1
#    while num < 1000000 :
#        carray[num] = count
#        num += num
#        count += 1
    
    while my_read(InputReader()) :
        my_eval()
        my_print(OutputWriter())

if __name__ == "__main__" :
    main()

